package cn.stylefeng.guns.modular.test.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.MinerHold;
import cn.stylefeng.guns.modular.test.service.IMinerHoldService;

/**
 * 测试生成控制器
 *
 * @author fengshuonan
 * @Date 2020-11-24 14:33:37
 */
@Controller
@RequestMapping("/minerHold")
public class MinerHoldController extends BaseController {

    private String PREFIX = "/test/minerHold/";

    @Autowired
    private IMinerHoldService minerHoldService;

    /**
     * 跳转到测试生成首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "minerHold.html";
    }

    /**
     * 跳转到添加测试生成
     */
    @RequestMapping("/minerHold_add")
    public String minerHoldAdd() {
        return PREFIX + "minerHold_add.html";
    }

    /**
     * 跳转到修改测试生成
     */
    @RequestMapping("/minerHold_update/{minerHoldId}")
    public String minerHoldUpdate(@PathVariable Integer minerHoldId, Model model) {
        MinerHold minerHold = minerHoldService.selectById(minerHoldId);
        model.addAttribute("item",minerHold);
        LogObjectHolder.me().set(minerHold);
        return PREFIX + "minerHold_edit.html";
    }

    /**
     * 获取测试生成列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return minerHoldService.selectList(null);
    }

    /**
     * 新增测试生成
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(MinerHold minerHold) {
        minerHoldService.insert(minerHold);
        return SUCCESS_TIP;
    }

    /**
     * 删除测试生成
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer minerHoldId) {
        minerHoldService.deleteById(minerHoldId);
        return SUCCESS_TIP;
    }

    /**
     * 修改测试生成
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(MinerHold minerHold) {
        minerHoldService.updateById(minerHold);
        return SUCCESS_TIP;
    }

    /**
     * 测试生成详情
     */
    @RequestMapping(value = "/detail/{minerHoldId}")
    @ResponseBody
    public Object detail(@PathVariable("minerHoldId") Integer minerHoldId) {
        return minerHoldService.selectById(minerHoldId);
    }
}
